#coding=utf-8
#Boa:Dialog:DlgDeliveryPlanChoice

import wx

from MyListCtrl import MyListCtrlDeliveryPlan
from product import CDataDeliveryState,CDataDeliveryPlan

def create(parent):
    return DlgDeliveryPlanChoice(parent)

[wxID_DLGDELIVERYPLANCHOICE, wxID_DLGDELIVERYPLANCHOICEBTNCHECK, 
 wxID_DLGDELIVERYPLANCHOICEBTNCHECKMALL, wxID_DLGDELIVERYPLANCHOICEBTNNEEDPIC, 
 wxID_DLGDELIVERYPLANCHOICEBTNPLANING, wxID_DLGDELIVERYPLANCHOICEBTNQUICKADD, 
 wxID_DLGDELIVERYPLANCHOICEBTNREJECT, 
 wxID_DLGDELIVERYPLANCHOICEBTNSHOWSENDING, 
] = [wx.NewId() for _init_ctrls in range(8)]

class DlgDeliveryPlanChoice(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DLGDELIVERYPLANCHOICE,
              name=u'DlgDeliveryPlanChoice', parent=prnt, pos=wx.Point(785,
              340), size=wx.Size(871, 479), style=wx.DEFAULT_DIALOG_STYLE,
              title=u'\u9001\u8d27\u8ba1\u5212')
        self.SetClientSize(wx.Size(855, 441))
        self.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              u'\u6977\u4f53_GB2312'))
        self.SetBackgroundColour(wx.Colour(183, 209, 173))
        self.Center(wx.BOTH)

        self.btnQuickAdd = wx.Button(id=wxID_DLGDELIVERYPLANCHOICEBTNQUICKADD,
              label=u'\u5feb\u901f\u65b0\u5efa\u8ba1\u5212',
              name=u'btnQuickAdd', parent=self, pos=wx.Point(16, 8),
              size=wx.Size(128, 26), style=0)
        self.btnQuickAdd.Bind(wx.EVT_BUTTON, self.OnBtnQuickAddButton,
              id=wxID_DLGDELIVERYPLANCHOICEBTNQUICKADD)

        self.btnReject = wx.Button(id=wxID_DLGDELIVERYPLANCHOICEBTNREJECT,
              label=u'\u53d6\u6d88\u9001\u8d27\u8ba1\u5212', name=u'btnReject',
              parent=self, pos=wx.Point(176, 8), size=wx.Size(128, 26),
              style=0)
        self.btnReject.Bind(wx.EVT_BUTTON, self.OnBtnRejectButton,
              id=wxID_DLGDELIVERYPLANCHOICEBTNREJECT)

        self.btnShowSending = wx.Button(id=wxID_DLGDELIVERYPLANCHOICEBTNSHOWSENDING,
              label=u'\u51fa\u8f66\u4e2d', name=u'btnShowSending', parent=self,
              pos=wx.Point(128, 48), size=wx.Size(85, 26), style=0)
        self.btnShowSending.Bind(wx.EVT_BUTTON, self.OnBtnShowSendingButton,
              id=wxID_DLGDELIVERYPLANCHOICEBTNSHOWSENDING)

        self.btnPlaning = wx.Button(id=wxID_DLGDELIVERYPLANCHOICEBTNPLANING,
              label=u'\u8ba1\u5212\u4e2d', name=u'btnPlaning', parent=self,
              pos=wx.Point(24, 48), size=wx.Size(93, 26), style=0)
        self.btnPlaning.Bind(wx.EVT_BUTTON, self.OnBtnPlaningButton,
              id=wxID_DLGDELIVERYPLANCHOICEBTNPLANING)

        self.btnCheck = wx.Button(id=wxID_DLGDELIVERYPLANCHOICEBTNCHECK,
              label=u'\u6574\u7406\u4e2d', name=u'btnCheck', parent=self,
              pos=wx.Point(224, 48), size=wx.Size(93, 26), style=0)
        self.btnCheck.Bind(wx.EVT_BUTTON, self.OnBtnCheckButton,
              id=wxID_DLGDELIVERYPLANCHOICEBTNCHECK)

        self.btnCheckMall = wx.Button(id=wxID_DLGDELIVERYPLANCHOICEBTNCHECKMALL,
              label=u'\u6574\u7406-\u7535\u5546', name=u'btnCheckMall',
              parent=self, pos=wx.Point(328, 48), size=wx.Size(93, 26),
              style=0)
        self.btnCheckMall.Bind(wx.EVT_BUTTON, self.OnBtnCheckMallButton,
              id=wxID_DLGDELIVERYPLANCHOICEBTNCHECKMALL)

        self.btnNeedPic = wx.Button(id=wxID_DLGDELIVERYPLANCHOICEBTNNEEDPIC,
              label=u'\u5f85\u622a\u56fe', name=u'btnNeedPic', parent=self,
              pos=wx.Point(432, 48), size=wx.Size(93, 26), style=0)
        self.btnNeedPic.Bind(wx.EVT_BUTTON, self.OnBtnNeedPicButton,
              id=wxID_DLGDELIVERYPLANCHOICEBTNNEEDPIC)

    def __init__(self, parent):
        self._init_ctrls(parent)
        
        self.lcPlan = MyListCtrlDeliveryPlan(self)
        self.lcPlan.Move(wx.Point(10, 90))
        self.lcPlan.SetSize(wx.Size(800, 300))
        self.lcPlan.refresh({'state':CDataDeliveryState.STATE_PLAN})#({'not_state':CDataDeliveryState.STATE_DONE})
        self.lcPlan.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)

    def getSelVal(self):
        return self.m_planId

    def OnLeftDClick(self, event):
        self.m_planId = self.lcPlan.getPlanId()
        self.EndModal(wx.ID_OK)
        
    def OnBtnQuickAddButton(self, event):
        import DlgRoute
        
        dlg = DlgRoute.create(self)
        if (dlg.ShowModal() != wx.ID_OK):
            return
        
        routeObj = dlg.getSelectObj()
        if not routeObj:
            return
        
        planObj = CDataDeliveryPlan.quickAdd(routeObj.getKeyVal())
        self.m_planId = planObj.getKeyVal()
        self.EndModal(wx.ID_OK)

    def OnBtnRejectButton(self, event):
        self.m_planId = ''
        self.EndModal(wx.ID_OK)

    def OnBtnShowSendingButton(self, event):
        self.lcPlan.refresh({'state':CDataDeliveryState.STATE_RUN})#({'not_state':CDataDeliveryState.STATE_DONE})

    def OnBtnPlaningButton(self, event):
        self.lcPlan.refresh({'state':CDataDeliveryState.STATE_PLAN})

    def OnBtnCheckButton(self, event):
        self.lcPlan.refresh({'state':CDataDeliveryState.STATE_CHECK})

    def OnBtnCheckMallButton(self, event):
        self.lcPlan.refresh({'state':CDataDeliveryState.STATE_CHECK_MALL})

    def OnBtnNeedPicButton(self, event):
        self.lcPlan.refresh({'state':CDataDeliveryState.STATE_NEED_PIC})
        
